﻿using DFGK.WMS.Common.Tools;
using DFGK.WMS.Common.Web;
using DFGK_WMS.IRepository;
using DFGK_WMS.Model.DTO;
using DFGK_WMS.Model.Models;
using DFGK_WMS.Repository;
using DFGK_WMS.WebAPI.Controllers.Result;
using DFGK_WMS.WebAPI.Tools;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.POIFS.Crypt.Dsig;

namespace DFGK_WMS.WebAPI.Controllers.设备
{
    /// <summary>
    /// AGV
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AGVController : ControllerBase
    {
        private readonly ILogRepository logRepository;
        public AGVController(ILogRepository logRepository)
        {
            this.logRepository = logRepository;
        }

        /// <summary>
        /// agv任务上报
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult TaskAppear(AgvDto dto)
        {
            TLog logg = new TLog();
            logg.LogType = 1;
            logg.ActionType = 4;
            logg.ModuleName = "接收AGV任务";
            logg.Status = 1;
            //var IsOk = logRepository.AddTLod(logg);
            
            if (dto.method == "end")
            {
                logg.Description = "接收AGV任务成功，执行成功";
                logRepository.AddTLod(logg);
                return Ok(BaseResult.ReturnInfo(0, "执行成功", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
            }
            logg.Description = "接收AGV任务成功，执行失败";
            logRepository.AddTLod(logg);
            return Ok(BaseResult.ReturnInfo(1, "执行失败", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
        }
        /// <summary>
        /// agv出入库任务
        /// </summary>
        /// <param name="agv"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult getTaskByWes(AGVRequestDto agv)
        {
            var agvdt = HttpHelper.AgvSendPostRequest("script-api/getTaskByWms", agv);
            LogHelper.Info("agv:" + agvdt);
            return Ok(BaseResult.ReturnInfo(0, agvdt, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
        }
    }
}
